﻿/* 
 * Since 2008 - 2012
 */

package com.hh.bss.auth.service.impl;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

import com.hh.bss.auth.client.OnlineUser;
import com.hh.bss.auth.dao.*;
import com.hh.bss.auth.entity.*;
import com.hh.bss.auth.service.*;
import com.hh.bss.auth.vo.query.*;
import com.hh.bss.base.*;
import com.hh.bss.common.MapObjectRowMapper;
import com.hh.bss.common.cache.SystemUserCache;
import com.hh.bss.common.page.*;
import com.hh.bss.common.page.impl.*;
import com.hh.bss.common.tree.BranchCompanyTreeNode;
import com.hh.bss.common.tree.CompanyCvTreeNode;
import com.hh.bss.common.tree.CompanyDeptTitleTreeNode;
import com.hh.bss.common.tree.CompanyDeptTreeNode;
import com.hh.bss.common.tree.TreeNode;
import com.hh.bss.customer.entity.CompanyDept;
import com.hh.bss.customer.entity.CompanyDeptTitle;
import com.hh.bss.project.entity.SearchProjectCv;
import com.hh.bss.talent.entity.CvSimple;
import com.hh.bss.util.*;




@Service
@Transactional
public class SystemBranchCompanyServiceImpl extends BaseBusinessService<SystemBranchCompany,java.lang.Integer>  implements SystemBranchCompanyService<SystemBranchCompany,java.lang.Integer>{

	private SystemBranchCompanyDao systemBranchCompanyDao;
	/**增加setXXXX()方法,spring就可以通过autowire自动设置对象属性,请注意大小写*/
	public void setSystemBranchCompanyDaoImpl(SystemBranchCompanyDao dao) {
		this.systemBranchCompanyDao = dao;
	}
	public EntityDao getEntityDao() {
		return this.systemBranchCompanyDao;
	}
	
	@Transactional(readOnly=true)
	public Page findPage(SystemBranchCompanyQuery query) {
		return systemBranchCompanyDao.findPage(query);
	}
	public void save(SystemBranchCompany systemBranchCompany){
		List l=systemBranchCompanyDao.getHibernateTemplate().find("from SystemBranchCompany t where t.branchNbr=?",systemBranchCompany.getBranchNbr());
		if(l!=null&&l.size()>0) throw new RuntimeException("分公司编码已存在，新增失败。");
		systemBranchCompanyDao.save(systemBranchCompany);
	}
	public void update(SystemBranchCompany systemBranchCompany){
		List l=systemBranchCompanyDao.getHibernateTemplate().find("from SystemBranchCompany t where t.branchNbr=?",systemBranchCompany.getBranchNbr());
		if(l!=null&&l.size()>0){
			SystemBranchCompany oldSystemBranchCompany=(SystemBranchCompany)l.get(0);
			if (!oldSystemBranchCompany.getId().equals(systemBranchCompany.getId()))
			   throw new RuntimeException("分公司编码已存在，新增失败。");
		}
		systemBranchCompanyDao.update(systemBranchCompany);
		systemBranchCompanyDao.flush();
	}
	public void removeById(Integer id){
		List l=systemBranchCompanyDao.getHibernateTemplate().find("from SystemBranchDept t where t.branchCompanyId=?",id);
		if(l!=null&&l.size()>0) throw new RuntimeException("分公司存在部门,不能删除");
		systemBranchCompanyDao.deleteById(id);
	}
	public List getOrg(){
		List rootCompany=this.getEntityDao().getHibernateTemplate().find("from SystemBranchCompany a where a.parentId=0 ");
		List nodeLists=new ArrayList();
		SystemBranchCompany company=null;
		BranchCompanyTreeNode root=null;
		BranchCompanyTreeNode child=null;
		
		if (rootCompany!=null&&rootCompany.size()>0){
			company=(SystemBranchCompany)rootCompany.get(0);
			//设置根公司节点
			root=new BranchCompanyTreeNode();
			root.setCompanyId(company.getId().toString());
			root.setParentId("0");
			root.setText(company.getName());	
			root.setId(company.getId().toString());
			List l=getOrg(company.getId());
			root.setChildren(l);
			List allChildCompany=this.getEntityDao().getHibernateTemplate().find("from SystemBranchCompany a where a.parentId=? ",company.getId());
			nodeLists.add(root);
			 for(int i=0;allChildCompany!=null&&i<allChildCompany.size();i++){
				 
				 company=(SystemBranchCompany)allChildCompany.get(i);
				 System.out.println("dsfdsfdsfdsf-----"+company.getName());
				 child=new BranchCompanyTreeNode();
				 child.setCompanyId(company.getId().toString());
				 child.setText(company.getName());
				 child.setId(company.getId().toString());
				 child.setParentId(company.getParentId().toString());
				 
				 l=getOrg(company.getId());
				 //child.addChildren(treeNode)
				 child.setChildren(l);
				 root.addChildren(child);
			 }
			
		}
		
		
		
		
		return nodeLists;
	}
	public List getOrg(Integer companyId){
		Object[] os={companyId};
		List allDeptList=this.getEntityDao().getHibernateTemplate().find("from SystemBranchDept a where a.branchCompanyId=? ", os);
		Map allDeptTreeNodeMap=new LinkedHashMap();
		//allDeptMap.keySet().
		SystemBranchDept companyDept=null;
		CompanyDeptTreeNode companyDeptTreeNode=null;
		for(int i=0;allDeptList!=null&&i<allDeptList.size();i++){
			
			companyDept=(SystemBranchDept)allDeptList.get(i);
			companyDeptTreeNode=new CompanyDeptTreeNode();
			companyDeptTreeNode.setParentId(ObjectUtils.toString(companyDept.getParentId()));
			companyDeptTreeNode.setText(companyDept.getName());					
			companyDeptTreeNode.setId(ObjectUtils.toString(companyDept.getBranchCompanyId())+companyDept.getId().toString());
			companyDeptTreeNode.setDeptId(companyDept.getId().toString());
			companyDeptTreeNode.setCompanyId(ObjectUtils.toString(companyDept.getBranchCompanyId()));
			
			allDeptTreeNodeMap.put(companyDept.getId(), companyDeptTreeNode);
		}
		
		//设置 子部门
		SystemBranchDept childDept=null;
		CompanyDeptTreeNode parentNode=null;
		CompanyDeptTreeNode childNode=null;
		for(int i=0;allDeptList!=null&&i<allDeptList.size();i++){
			childDept=(SystemBranchDept)allDeptList.get(i);
			parentNode=(CompanyDeptTreeNode)allDeptTreeNodeMap.get(childDept.getParentId());
			childNode=(CompanyDeptTreeNode)allDeptTreeNodeMap.get(childDept.getId());
			if (parentNode!=null&&childNode!=null) parentNode.addChildren(childNode);			
		}
		
		
		
		
		//查询所有的职位
		List allTitleList=this.getEntityDao().getHibernateTemplate().find("from SystemBranchTitle dt where dt.deptId in (select a.id from SystemBranchDept a where a.branchCompanyId=?) ", os);
		
		Map allTitleTreeNodeMap=new LinkedHashMap();
		SystemBranchTitle companyDeptTitle=null;
		CompanyDeptTreeNode one=null;
		CompanyDeptTitleTreeNode companyDeptTitleTreeNode=null;
		CompanyDeptTitleTreeNode conTitle=null;
         for(int i=0;allTitleList!=null&&i<allTitleList.size();i++){
			
        	companyDeptTitle=(SystemBranchTitle)allTitleList.get(i);
        	companyDeptTitleTreeNode=new CompanyDeptTitleTreeNode();
        	companyDeptTitleTreeNode.setParentId(ObjectUtils.toString(companyDeptTitle.getParentId()));
        	companyDeptTitleTreeNode.setText(companyDeptTitle.getName());		
        	companyDeptTitleTreeNode.setCompanyId(ObjectUtils.toString(companyId));
        	companyDeptTitleTreeNode.setTitleId(companyDeptTitle.getId().toString());
        	companyDeptTitleTreeNode.setDeptId(ObjectUtils.toString(companyDeptTitle.getDeptId()));
        	companyDeptTitleTreeNode.setId(ObjectUtils.toString(companyDeptTitle.getDeptId())+ObjectUtils.toString(companyDeptTitle.getDeptId())+companyDeptTitle.getId().toString());
			
        	one=(CompanyDeptTreeNode)allDeptTreeNodeMap.get(companyDeptTitle.getDeptId());
        	//没有父岗位的，设置到部门下
			if (one!=null&&(StringHelper.isEmpty(companyDeptTitleTreeNode.getParentId())||"0".equals(companyDeptTitleTreeNode.getParentId()))) one.addChildren(companyDeptTitleTreeNode);
			//if (one!=null) one.addChildren(companyDeptTitleTreeNode);
			
			allTitleTreeNodeMap.put(companyDeptTitle.getId(), companyDeptTitleTreeNode);
		}
       //设置员工
         
         
         /*
         List allUserList=this.getEntityDao().getHibernateTemplate().find("from SystemUser  ");
         CompanyCvTreeNode companyCvTreeNode=null;
         SystemUser systemUser=null;
         for(int i=0;allUserList!=null&&i<allUserList.size();i++){
        	 systemUser=(SystemUser)allUserList.get(i);
        	 companyCvTreeNode=new CompanyCvTreeNode();
        	 companyCvTreeNode.setText(systemUser.getName());
        	 companyCvTreeNode.setCompanyId(ObjectUtils.toString(systemUser.getBranchCompanyId()));
        	 companyCvTreeNode.setDeptId(ObjectUtils.toString(systemUser.getDeptId()));
        	 companyCvTreeNode.setTitleId(ObjectUtils.toString(systemUser.getTitleId()));
        	 companyCvTreeNode.setCvId(systemUser.getId().toString());
        	 
        	 
        	 CompanyDeptTitleTreeNode titleTree=(CompanyDeptTitleTreeNode)allTitleTreeNodeMap.get(systemUser.getTitleId());
        	 if (titleTree!=null){
        		 
        		 companyCvTreeNode.setId(titleTree.getId()+systemUser.getId());
        		 titleTree.addChildren(companyCvTreeNode);
        	 }
         }
         */
         List values = new ArrayList();
 		 StringBuffer sql = new StringBuffer();
 		 sql.append("select d.name userName,d.status,c.branch_company_id branchCompanyId,a.title_id titleId,b.dept_id deptId,a.user_id userId from system_user_title a,system_branch_title b,system_branch_dept c,system_user d where a.title_id=b.id and b.dept_id=c.id and a.user_id=d.id ");
 		 
         List allUserList=this.getEntityDao().getJdbcDao().findByQuery(sql.toString(),values.toArray(), new MapObjectRowMapper());
         CompanyCvTreeNode companyCvTreeNode=null;
         Map m=null;
         
         for(int i=0;allUserList!=null&&i<allUserList.size();i++){
        	 m=(Map)allUserList.get(i);
        	 companyCvTreeNode=new CompanyCvTreeNode();
        	 //N-正常 B-锁定(离职)
        	 if("N".equals((String)m.get("status"))){
        		 companyCvTreeNode.setText((String)m.get("userName"));    
        	 }
        	 if("B".equals((String)m.get("status"))){
        		 companyCvTreeNode.setText((String)m.get("userName")+"(离职)");    
        	 }
        	 companyCvTreeNode.setCompanyId(ObjectUtils.toString(m.get("BranchCompanyId")));
        	 companyCvTreeNode.setDeptId(ObjectUtils.toString(m.get("deptId")));
        	 companyCvTreeNode.setTitleId(ObjectUtils.toString(m.get("titleId")));
        	 companyCvTreeNode.setCvId(ObjectUtils.toString(m.get("userId")));
        	         	 
        	 CompanyDeptTitleTreeNode titleTree=(CompanyDeptTitleTreeNode)allTitleTreeNodeMap.get(m.get("titleId"));
        	 if (titleTree!=null){        		 
        		 companyCvTreeNode.setId(titleTree.getId()+m.get("titleId")+m.get("userId"));
        		 titleTree.addChildren(companyCvTreeNode);
        	 }
         }
         
       //设置 子岗位 
         CompanyDeptTitleTreeNode parentTitleNode=null;
         CompanyDeptTitleTreeNode childTitleNode=null;
         SystemBranchTitle childTitle=null;       
         for(int i=0;allTitleList!=null&&i<allTitleList.size();i++){
 			childTitle=(SystemBranchTitle)allTitleList.get(i);
 			parentTitleNode=(CompanyDeptTitleTreeNode)allTitleTreeNodeMap.get(childTitle.getParentId());
 			childTitleNode=(CompanyDeptTitleTreeNode)allTitleTreeNodeMap.get(childTitle.getId());
 			
 			//找不到父岗位的，将其设置到部门下
			
			//if (one!=null&&(StringHelper.isEmpty(companyDeptTitleTreeNode.getParentId())||"0".equals(companyDeptTitleTreeNode.getParentId())||parentTitleNode==null)) one.addChildren(companyDeptTitleTreeNode);
 			//if (parentTitleNode==null&&childTitleNode!=null&&childTitle.getParentId()!=null&&childTitle.getParentId().intValue()!=0){ 				
 			if (parentTitleNode==null&&childTitleNode!=null&&childTitle.getParentId()!=null&&childTitle.getParentId().intValue()!=0){
 	        	one=(CompanyDeptTreeNode)allDeptTreeNodeMap.get(childTitle.getDeptId());
 	        	if (one!=null) one.addChildren(childTitleNode);
 				
 			}else if (parentTitleNode!=null&&childTitleNode!=null&&parentTitleNode.getDeptId()!=null&&parentTitleNode.getDeptId().equals(childTitleNode.getDeptId())) { 				
 				 //有父岗位，且父子岗位的部门一致				    			
 				   parentTitleNode.addChildren(childTitleNode);
 				
 			}else{
 				//否则还是挂在部门下
 				one=(CompanyDeptTreeNode)allDeptTreeNodeMap.get(childTitle.getDeptId());
 	        	if (one!=null) one.addChildren(childTitleNode);
 			}
 		}
        
         
		
         List nodeLists=new ArrayList();
         
         for(Iterator it=allDeptTreeNodeMap.values().iterator();it.hasNext();){
    		 CompanyDeptTreeNode oneDept=(CompanyDeptTreeNode)it.next();
    		 if (StringHelper.isEmpty(oneDept.getParentId())||"0".equals(oneDept.getParentId())) nodeLists.add(oneDept);    		 
    		 else if (allDeptTreeNodeMap.get(StringHelper.parseInteger(oneDept.getParentId(), 0))==null) nodeLists.add(oneDept);
    	 }
         
         //oneTreeNode= (TreeNode)allDeptTreeNodeMap.get(deptId);
    	 //if (oneTreeNode!=null) nodeLists.add(oneTreeNode);
         //System.out.println(companyId+"--------"+nodeLists.);
		return nodeLists;
	}
	public SystemBranchCompany getByNbr(String nbr) {
		// TODO Auto-generated method stub
		SystemBranchCompany systemBranchCompany=null;
		List l=systemBranchCompanyDao.getHibernateTemplate().find("from SystemBranchCompany t where t.branchNbr=?",nbr);
		if(l!=null&&l.size()>0) systemBranchCompany=(SystemBranchCompany)l.get(0);
		return systemBranchCompany;
	}

	private void traverseTree(CompanyCvTreeNode parentNode,List child,Map companyMap,Map deptMap,Map titleMap,Map cvMap){
		CompanyCvTreeNode companyCvTreeNode=null;
		for(int i=0;child!=null&&i<child.size();i++){
			
			if (!(child.get(i) instanceof CompanyCvTreeNode)){
				System.out.println("异常数据："+i+"  "+child.get(i).getClass().getName());
				System.out.println("异常数据："+i);
				continue;
			}
			
			companyCvTreeNode=(CompanyCvTreeNode)child.get(i);
			//System.out.println(companyCvTreeNode.getCompanyNodeType()+"-company-"+companyCvTreeNode.getCompanyId()+"-dept-"+companyCvTreeNode.getDeptId()+"-title-"+companyCvTreeNode.getTitleId()+"-child data:"+child.get(i));
			
			
//			if (true) break;
			if ("COMPANY".equals(companyCvTreeNode.getCompanyNodeType())){
				//如果子节点是公司，则不做处理更新处理
				companyMap.put(companyCvTreeNode.getCompanyId(), companyCvTreeNode);
				
			}else if ("DEPT".equals(companyCvTreeNode.getCompanyNodeType())){
				//如果子节点是部门，则更新部门的上级部门和所属公司
				companyCvTreeNode.setCompanyId(parentNode.getCompanyId());
				
				
				
				if ("COMPANY".equals(parentNode.getCompanyNodeType())){					
					companyCvTreeNode.setParentId("0");
					companyCvTreeNode.setParentIds("/"+companyCvTreeNode.getDeptId()+"/");
				}else {									
					companyCvTreeNode.setParentId(parentNode.getDeptId());
					companyCvTreeNode.setParentIds(parentNode.getParentIds()+companyCvTreeNode.getDeptId()+"/");
				}
				deptMap.put(companyCvTreeNode.getDeptId(), companyCvTreeNode);
				
			}else if ("TITLE".equals(companyCvTreeNode.getCompanyNodeType())){
				//如果子节点是岗位，则更新岗位的上级和所属部门
				companyCvTreeNode.setDeptId(parentNode.getDeptId());
				companyCvTreeNode.setCompanyId(parentNode.getCompanyId());
				
								
				if ("DEPT".equals(parentNode.getCompanyNodeType())){						
					companyCvTreeNode.setParentIds("/"+companyCvTreeNode.getTitleId()+"/");
					companyCvTreeNode.setParentId("0");
				}else {									
					companyCvTreeNode.setParentId(parentNode.getTitleId());
					companyCvTreeNode.setParentIds(parentNode.getParentIds()+companyCvTreeNode.getTitleId()+"/");
				}
				titleMap.put(companyCvTreeNode.getTitleId(), companyCvTreeNode);
				
			}else if ("CV".equals(companyCvTreeNode.getCompanyNodeType())){
				//如果子节点是人员，则更新所属岗位
				companyCvTreeNode.setDeptId(parentNode.getDeptId());
				companyCvTreeNode.setCompanyId(parentNode.getCompanyId());
				companyCvTreeNode.setTitleId(parentNode.getTitleId());
				
				List l=(List)cvMap.get(companyCvTreeNode.getCvId());
				if (l==null) {
					l=new ArrayList();					
					cvMap.put(companyCvTreeNode.getCvId(), l);					
				}
				l.add(companyCvTreeNode);
				
			}
			
			//子节点
			traverseTree(companyCvTreeNode,companyCvTreeNode.getChildren(),companyMap,deptMap,titleMap,cvMap);
			
		}
	}
	@Override
	public void saveOrgTree(OnlineUser onlineUser,CompanyCvTreeNode root) {
		// TODO Auto-generated method stub
		
		//根节点--分公司--部门-岗位-个人
		//CompanyCvTreeNode root=null;
		if (root!=null){
			//root=(CompanyCvTreeNode)tree.get(0);
			//root=
			//取分公司id-Object
			//取部门id-Object
			//取岗位id-Object
			//取个人 id-List
			Map companyMap=new HashMap();
			Map deptMap=new HashMap();
			Map titleMap=new HashMap();
			Map cvMap=new HashMap();
			boolean isModify=false;
			traverseTree(root,root.getChildren(),companyMap,deptMap,titleMap,cvMap);
			
			//分公司不用处理
			//处理部门
			SystemBranchDept systemBranchDept=null;
			CompanyCvTreeNode one=null;
			for(Iterator it=deptMap.keySet().iterator();it.hasNext();){
				String deptId=(String)it.next();
				one=(CompanyCvTreeNode)deptMap.get(deptId);
				try{
					
					systemBranchDept=systemBranchCompanyDao.getHibernateTemplate().get(SystemBranchDept.class, StringHelper.parseInteger(deptId, 0));
					if (systemBranchDept==null){
						System.out.println("部门 null:"+deptId);
						continue;
					}
					//如果改变，则更新
					if ((!StringHelper.parseInteger(one.getCompanyId(), 0).equals(systemBranchDept.getBranchCompanyId()))||(!StringHelper.parseInteger(one.getParentId(), 0).equals(systemBranchDept.getParentId()))){
						systemBranchDept.setBranchCompanyId(StringHelper.parseInteger(one.getCompanyId(), 0));
						systemBranchDept.setParentId(StringHelper.parseInteger(one.getParentId(), 0));
						systemBranchDept.setParentIds(one.getParentIds());
					    systemBranchCompanyDao.getHibernateTemplate().save(systemBranchDept);
					    isModify=true;
						System.out.println("更新部门id:"+systemBranchDept.getId()+" 公司id:"+one.getCompanyId()+" 上级id:"+one.getParentId());	
					}
					
				}catch(Exception ex){ex.printStackTrace();}
				
			}
			//////systemBranchCompanyDao.flush();
			//处理岗位
			SystemBranchTitle systemBranchTitle=null;
			for(Iterator it=titleMap.keySet().iterator();it.hasNext();){
				String titleId=(String)it.next();
				one=(CompanyCvTreeNode)titleMap.get(titleId);
				try{
					systemBranchTitle=systemBranchCompanyDao.getHibernateTemplate().get(SystemBranchTitle.class, StringHelper.parseInteger(titleId, 0));
					if (systemBranchTitle==null) {
						System.out.println("岗位null:"+titleId);
						continue;
					}
					//如果改变，则更新
					if ((!StringHelper.parseInteger(one.getDeptId(), 0).equals(systemBranchTitle.getDeptId()))||(!StringHelper.parseInteger(one.getParentId(), 0).equals(systemBranchTitle.getParentId())))
					{
						systemBranchTitle.setDeptId(StringHelper.parseInteger(one.getDeptId(), 0));
						systemBranchTitle.setParentId(StringHelper.parseInteger(one.getParentId(), 0));
						systemBranchTitle.setParentIds(one.getParentIds());
				    	systemBranchCompanyDao.getHibernateTemplate().update(systemBranchTitle);
				    	isModify=true;
						System.out.println("更新岗位id:"+systemBranchTitle.getId()+" 部门id:"+one.getDeptId()+" 上级id:"+StringHelper.parseInteger(one.getParentId(), 0));	
					}
					
				}catch(Exception ex){ex.printStackTrace();}
				
			}
			systemBranchCompanyDao.flush();
			//处理人员（所属岗位）
			CompanyCvTreeNode cvTitleNode=null;
			for(Iterator it=cvMap.keySet().iterator();it.hasNext();){
				String cvId=(String)it.next();
				List titleIds=(List)cvMap.get(cvId);
				
				if (StringHelper.parseInt(cvId, 0)==0) continue;
				//查询已有的
				List l=systemBranchCompanyDao.getHibernateTemplate().find("from SystemUserTitle t where t.userId=?",StringHelper.parseInteger(cvId, 0));
				
				//删除
				SystemUserTitle systemUserTitle=null;
				SystemUserTitle newSystemUserTitle=null;
				for (int j=0;l!=null&&j<l.size();j++){
					systemUserTitle=(SystemUserTitle)l.get(j);
					boolean isDelete=true;
					for(int i=0;titleIds!=null&&i<titleIds.size();i++){		
						cvTitleNode=(CompanyCvTreeNode)titleIds.get(i);
					    if (systemUserTitle.getTitleId().equals(StringHelper.parseInteger(cvTitleNode.getTitleId(), 0))) isDelete=false;
					}	
					if (isDelete){
					
						systemBranchCompanyDao.getHibernateTemplate().delete(systemUserTitle);
						System.out.println("删除人员岗位:"+systemUserTitle.getUserId()+"--"+systemUserTitle.getTitleId());
						isModify=true;
						systemBranchCompanyDao.flush();
					}
				}
				//新增
				
				//for(int i=0;titleIds!=null&&titleIds.length>0&&i<titleIds.length;i++){
				  for(int i=0;titleIds!=null&&i<titleIds.size();i++){	
				    boolean isAdd=true;
				    cvTitleNode=(CompanyCvTreeNode)titleIds.get(i);
				    
				    for (int j=0;l!=null&&j<l.size();j++){
						systemUserTitle=(SystemUserTitle)l.get(j);
						if (systemUserTitle.getTitleId().equals(StringHelper.parseInteger(cvTitleNode.getTitleId(), 0))) isAdd=false;
				    }
				    if (StringHelper.parseInt(cvTitleNode.getTitleId(), 0)==0) continue;
				    newSystemUserTitle=new SystemUserTitle();
				    newSystemUserTitle.setUserId(StringHelper.parseInteger(cvId, 0));
				    newSystemUserTitle.setTitleId(StringHelper.parseInteger(cvTitleNode.getTitleId(), 0));
				    newSystemUserTitle.setCreator(onlineUser.getUsername());
				    newSystemUserTitle.setCreateDt(new Date());
				    if (isAdd){
				    	systemBranchCompanyDao.getHibernateTemplate().save(newSystemUserTitle);
				    	System.out.println("新增人员岗位:"+newSystemUserTitle.getUserId()+"--"+newSystemUserTitle.getTitleId());
				    	systemBranchCompanyDao.flush();
				    	isModify=true;
				    }
				}
				

				
			}
			//如果有改变则刷新缓存
			if (isModify) SystemUserCache.refresh();
			
			
		}
		
		
	}
}
